package com.example.education.controller;

import com.example.education.exception.ParamException;
import com.example.education.model.Reply;
import com.example.education.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/interface/reply")
public class ReplyController {

    @Autowired
    ReplyService replyService;

    @RequestMapping("/insert")
    public boolean insertReply(Reply reply){
        boolean result = false;
        try {
            result = replyService.insertReply(reply);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/delete")
    public boolean deleteReply(Integer replyId){
        boolean result = false;
        try {
            result = replyService.deleteReply(replyId);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/like")
    public boolean likeReply(Integer replyId){
        boolean result = false;
        try {
            result = replyService.likeReply(replyId);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/getById")
    public Reply getReplyById(Integer replyId){
        Reply reply = new Reply();
        try {
            reply = replyService.getReplyById(replyId);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return reply;
    }

    @RequestMapping("/getByCateAndPid")
    public List<Reply> getRelyByCateAndPid(Integer cate, Integer pid){
        List<Reply> replies = new ArrayList<>();
        try {
            replies = replyService.getRelyByCateAndPid(cate,pid);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return replies;
    }
}
